<?php
function ping($host, $port, $timeout) {

  $tB = microtime(true);

  $fP = fSockOpen($host, $port, $errno, $errstr, $timeout);

  if (!$fP) { return "Can not connect to $host:$port"; }

  $tA = microtime(true);

  return round((($tA - $tB) * 1000), 0)." ms";

} 



echo ping("localhost", 25, 10); 

?>